<?php
//echo "ok ".IsLoggedIn();
if (!IsLoggedIn()) {

   /*// $clientId=getClientIdByMail(getSession("login"));

if ($clientId)
{

	header("Location: ".createNiceUrl("pageName","client_area"));
	exit;
}

if (getParameter("login") && getParameter("password") && !getParameter("SubmitLogin"))
{
	portalLogin(getParameter("login"),TEAdecrypt(getParameter("password"),KEY));

}
*/


?>



<div id="login">


<!-- <h1><?php echo $var_portal_login; ?></h1>  -->

    <?php


    if (getParameter("resendactivationlink")){

        $mail=getParameter("resendactivationlink");

       // echo $mail;
        $key=TEAencrypt($mail,KEY);
        $host=$_SERVER['HTTP_HOST'];
        if (isLocal())  $host=getPortalUrl().".betasite.net";
        $link="http://".$host."/?pageName=client_area&key=".$key;


        $data=array();
        $data["link"]=$link;
        $data["portal"]=getPortalName();
        $data["customer"]=getUserFullname();
        sendMailTo($mail, TemplateWithData($var_portal_mail_accountsaved,$data));
        ShowSuccess($var_portal_activation_sent);
    }

    $error=false;


    if (getParameter("SubmitLogin"))

    {

        if (getParameter($portletUID."email")==null || ew_CheckEmail(getParameter($portletUID."email"))==FALSE) displayError($var_portal_validmailerror,$portletUID."email");
        if (getParameter($portletUID."passwd")==null ) displayError($var_portal_invalidpassword,$portletUID."passwd");

        if ($error==false)
        {
            $mail=getParameter($portletUID."email");
            $password=getParameter($portletUID."passwd");

            //$redirect=createNiceUrl("pageName",getParameter("pageName"));
            $redirect=null;

            if (getParameter("backurl")!=null) $redirect=decryptUrl(getParameter("backurl"));
           $validpwd=portalLogin($mail,$password,$redirect);

         if ($redirect!=null) {
         	header("Location: ".$redirect);
         	exit;
         }
         
        if ($portlet_portal_login_Back_Url!="") {
        	
        	$redirect=createNiceUrl("pageName",$portlet_portal_login_Back_Url,"type","succes","key","loggedin");
         	header("Location: ".$redirect);
        	exit;
        }
         
        // ShowSuccess($var_portal_password_sent);
        }

    }

  //  echo $error;
    if ((getParameter("SubmitLogin")!=null && $error==true) || getParameter("SubmitLogin")==null) {


	if (getParameter("lostpassword")){
		
				$error=false;

				$mail=getParameter($portletUID."email");
				if ($mail==null || ew_CheckEmail($mail)==FALSE) displayError($var_portal_validmailerror,$portletUID."email");


                       // echo getClientIdByMail($mail);
                 if (getClientIdByMail($mail)=="") {

                     ShowError($var_portal_accountnotfound);
                     $error=true;
                 }

				if (!$error){




		$host=EW_PORTAL_URL;
		if (isLocal())  $host=getPortalUrl().".betasite.net";
		$link="http://".$host;

                    $data=array();
                    $data["link"]=$link;
                    $data["email"]=$mail;
                    $data["username"]=getUserFullname($mail);
                    $data["password"]=getUserPassword($mail);
                    sendMailTo($mail, TemplateWithData($var_portal_mail_passwordsent,$data));

				ShowSuccess($var_portal_password_sent);
				}
			}
			?>




	<form class="std  " id="login_form" method="post" action="<?php echo createNiceUrl("pageName",getParameter("pageName")); ?>">
        <input type="hidden" name="backurl" value="<?=getParameter("backurl")?>">
	<!-- <h3><?php echo $var_portal_Alreadyin; ?></h3> -->
		<fieldset>

			<p class="text">
				<label for="email"><?php echo $var_portal_createaccount_mail; ?></label>
				<span><?php formText($portletUID."email",0,"account_input"); ?>  </span>
			</p>
			<p class="text">
				<label for="passwd"><?php echo $var_portal_password; ?></label>
				<span><?php formPassword($portletUID."passwd",0,"account_input"); ?></span>
			</p>
			<p class="submit">
				<input type="hidden" value="my-account.php" name="back" class="hidden">				<input type="submit" value="<?php echo $var_portal_Login; ?>" class="button" name="SubmitLogin" id="SubmitLogin">
				<input type="submit" value="<?php echo $var_portal_passwordforgot; ?>" class="button" name="lostpassword" id="lostpassword">
			</p>
			<!-- <p class="lost_password"><a href="<?php echo  createUrl("action","lostpassword",$portletUID."email",getParameter($portletUID."email"));?>">Mot de passe oublié ?</a>  -->

		</fieldset>

	</form>




						</div>

<?php
    }
}else{

    $redirect=createNiceUrl("pageName",$portlet_portal_login_Back_Url);
	header("Location: ".$redirect);


}
?>